//
//  ST_VideoPreviewCell.swift
//  BTVideo
//
//  Created by DouLei on 2019/8/2.
//  Copyright © 2019 DouLei. All rights reserved.
//

import UIKit
import SDWebImage
import SwifterSwift

class ST_VideoPreviewCell: UICollectionViewCell {
 
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        
        contentView.addSubview(video_image_view)
        video_image_view.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
        contentView.addSubview(gradient)
        gradient.snp.makeConstraints { (make) in
            make.left.bottom.right.equalToSuperview()
            make.height.equalTo(60)
        }
        
        contentView.addSubview(sign_btn)
        sign_btn.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(5)
            make.bottom.equalToSuperview().offset(-5)
        }
        
        
        contentView.addSubview(reject_btn)
        reject_btn.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(30)
        }
        
        contentView.addSubview(cover_mark_label)
        cover_mark_label.snp.makeConstraints { (make) in
            make.width.equalTo(36)
            make.height.equalTo(18)
            make.left.equalToSuperview().offset(5)
            make.top.equalToSuperview().offset(5)
        }
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        contentView.cornerRadius = 5
    }
    
//    MARK: - Peroperties
    lazy var gradient:ST_FWGradientView = {
        let control = ST_FWGradientView()
        
        control.bgLayer.colors = [UIColor(red: 0, green: 0, blue: 0, alpha: 0).cgColor, UIColor(red: 0, green: 0, blue: 0, alpha: 0.8).cgColor]
        control.bgLayer.locations = [0, 1]
        control.bgLayer.startPoint = CGPoint(x: 0, y: 0.33)
        control.bgLayer.endPoint = CGPoint(x: 0, y: 1)
        return control
    }()
    
    lazy var video_image_view:UIImageView = {
        let control = UIImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        control.cornerRadius = 5
        return control
    }()
    
    lazy var sign_btn:UIButton = {
        
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        
        control.setTitleForAllStates("")
        
        control.titleLabel?.font = UIFont.systemFont(ofSize: 12, weight: UIFont.Weight.regular)
        
        control.titleEdgeInsets = UIEdgeInsets.init(top: 0, left: 10, bottom: 0, right: 0)
        
        control.setTitleColorForAllStates(.white)
        
        control.setImageForAllStates(ST_ImageUtils.imageName("mycenter_icon_弹幕")!)
        
//        control.setImage(ST_ImageUtils.imageName("UserCenter_mycenter_icon_审核"), for: UIControl.State.selected)
        
        return control
    }()
    
    lazy var cover_mark_label:UILabel = {
       let control = UILabel()
        control.text = "封面"
        control.font = UIFont.systemFont(ofSize: 12, weight: UIFont.Weight.regular)
        control.textColor = Color.white
        control.backgroundColor = Color.init(hexString: "#FEC207")
        control.cornerRadius = 4
        control.textAlignment = .center
        control.isHidden = true
        return control
    }()
    
    lazy var reject_btn:UIButton = {
        
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        
        control.setTitleForAllStates("审核未通过")
        
        control.titleLabel?.font = UIFont.systemFont(ofSize: 12, weight: UIFont.Weight.regular)
        
//        control.titleEdgeInsets = UIEdgeInsets.init(top: 0, left: 4, bottom: 0, right: 0)
        let color =  UIColor.init(hexString: "#E63030", transparency: 0.8)
        control.setTitleColorForAllStates(.white)
        
        control.setImageForAllStates(ST_ImageUtils.imageName("mycenter_icon_审核")!)
        
        control.backgroundColor = color
//        control.setImage(ST_ImageUtils.imageName("UserCenter_mycenter_icon_审核"), for: UIControl.State.selected)
        control.isHidden = true
        
        return control
    }()
    

//    MARK: - Bind Model
    var model = UserPreviewVideoModel(){
        didSet{
            
//            1=>'待审核',2=>'审核通过',3=>'审核未通过'
            if self.model.state == 3{
                
                sign_btn.isHidden = true
                reject_btn.isHidden = false
                reject_btn.setTitleForAllStates("审核未通过")
            }
            else if self.model.state == 1{
                
                sign_btn.isHidden = true
                reject_btn.isHidden = false
                reject_btn.setTitleForAllStates("审核中")
                
            }else{
                
                sign_btn.isHidden = false
                reject_btn.isHidden = true
                sign_btn.setTitleForAllStates(model.comment_times.string + "    ")
            }
            
            video_image_view.pin_setImage(from: model.cover_img.compress_image().url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
        }
    }
    
    var display_cover_mark = false{
        didSet{
            cover_mark_label.isHidden = !display_cover_mark
        }
    }
    
}
